<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Testen mehrerer Dateien</title>
</head>

<body bgcolor="FFFFFF">

<h1>Testen mehrerer Dateien</h1>

<p>In the classroom example, you will have many files that you wish to test
for their equivalence, and you won't want to read the output for each
of the student's solutions.</p>

<h2>Building comparison into the circuit</h2>

<p>One approach is to build a test circuit that does the comparison directly.
Here, we create an additional circuit within the testing file that contains
our solution circuit. In our overall testing circuit, we include both the
subcircuit from <tt>adder-master.circ</tt> and the subcircuit from the solution
circuit located directly into the nested circuit. We wire it so that there is
just one output, which is 1 as long as the two subcircuits agree.</p>

<blockquote><img src="../../../img-guide/verify-adder-test2.png"></blockquote>

<p>Now we can simply run Logisim substituting each query file. For any correct
solution, the only output will be <q>1</q>.</p>

<h2>Using redirection and shell scripts</h2>

<p>If you're quite comfortable with the command line,
you can build your own shell script to accomplish this.
Here, we'll use redirection (the &gt; operator) to save the output of each
circuit into a file.
For instance, we might issue the following two commands to collect the output
of the master circuit and the query circuit. 

<blockquote><tt>java&nbsp;-jar&nbsp;logisim-filename.jar&nbsp;adder-test.circ&nbsp;-tty&nbsp;table&nbsp;&gt;&nbsp;output-master.txt
<br>java&nbsp;-jar&nbsp;logisim-filename.jar&nbsp;adder-test.circ&nbsp;-tty&nbsp;table&nbsp;-sub&nbsp;adder-master.circ&nbsp;adder-query.circ&nbsp;&gt;&nbsp;output-query.txt</tt></blockquote>

<p>Now we've created two different files.
We can then compare the two output files using a program built for that purpose.
Under Linux or MacOS X, you might want to use the <em>cmp</em> or <em>diff</em>
command-line utilities. Under Windows, you might want to use WinMerge.</p>

<p>To process several query files, you would like want to build a simple program
such as a shell script to iterate through each and comparing the output.
Here is how I would do it under Linux's <em>bash</em>:</p>

<blockquote><tt>RUN_TEST="java&nbsp;-jar&nbsp;logisim-filename.jar&nbsp;adder-test.circ&nbsp;-tty&nbsp;table"<br>
${RUN_TEST}&nbsp;&gt;&nbsp;output-master.txt<br>
for&nbsp;QUERY_FILE&nbsp;in&nbsp;adder-query*.circ<br>
do<br>
&nbsp;&nbsp;if&nbsp;${RUN_TEST}&nbsp;-sub&nbsp;adder-master.circ&nbsp;${QUERY_FILE}&nbsp;|&nbsp;cmp&nbsp;-s&nbsp;output-master.txt<br>
&nbsp;&nbsp;then<br>
&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"${QUERY_FILE}&nbsp;OK"<br>
&nbsp;&nbsp;else<br>
&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;"${QUERY_FILE}&nbsp;different"<br>
&nbsp;&nbsp;fi<br>
done</tt></blockquote>

<p><strong>Weiter:</strong> <em><a href="../index.html"><em>Leitfaden für Benutzer von Logisim</em></a></em>.</p>

</body>
</html>
